package com.wmeimob.fastboot.jiubei.service;

import com.wmeimob.fastboot.jiubei.entity.Member;
import com.wmeimob.fastboot.jiubei.mapper.MemberMapper;
import com.wmeimob.fastboot.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version 1.0
 * @ClassName MemberServiceImpl
 * @Description 会员表 服务类实现
 * @Author wjt
 * @Date Mon Aug 24 21:15:22 CST 2020
 **/

@Service
@Transactional(rollbackFor = {Exception.class})
@Slf4j
public class MemberServiceImpl implements MemberService {

    @Resource
    private MemberMapper memberMapper;


    @Override
    public List<Member> list(Member member) {
        Example example = new Example(Member.class);
        Example.Criteria criteria = example.createCriteria();
        if (!StringUtils.isEmpty(member.getId())) {
            criteria.andEqualTo("id", member.getId());
        }
        if (!StringUtils.isEmpty(member.getVipNo())) {
            criteria.andLike("vipNo", StringUtils.fullFuzzy(member.getVipNo()));
        }
        if (!StringUtils.isEmpty(member.getNickname())) {
            criteria.andLike("nickname", StringUtils.fullFuzzy(member.getNickname()));
        }
        if (!StringUtils.isEmpty(member.getFullName())) {
            criteria.andLike("fullName", StringUtils.fullFuzzy(member.getFullName()));
        }
        if (!StringUtils.isEmpty(member.getPhone())) {
            criteria.andLike("phone", StringUtils.fullFuzzy(member.getPhone()));
        }
        if (!StringUtils.isEmpty(member.getSex())) {
            criteria.andEqualTo("sex", member.getSex());
        }
        if (!StringUtils.isEmpty(member.getHeadImg())) {
            criteria.andLike("headImg", StringUtils.fullFuzzy(member.getHeadImg()));
        }
        if (!StringUtils.isEmpty(member.getGmtRegister())) {
            criteria.andEqualTo("gmtRegister", member.getGmtRegister());
        }
        if (!StringUtils.isEmpty(member.getPayPwd())) {
            criteria.andLike("payPwd", StringUtils.fullFuzzy(member.getPayPwd()));
        }
        if (!StringUtils.isEmpty(member.getLevel())) {
            criteria.andEqualTo("level", member.getLevel());
        }
        if (!StringUtils.isEmpty(member.getWinningProbability())) {
            criteria.andEqualTo("winningProbability", member.getWinningProbability());
        }
        if (!StringUtils.isEmpty(member.getUpperId())) {
            criteria.andEqualTo("upperId", member.getUpperId());
        }
        if (!StringUtils.isEmpty(member.getUpperName())) {
            criteria.andLike("upperName", StringUtils.fullFuzzy(member.getUpperName()));
        }
        if (!StringUtils.isEmpty(member.getMoreUpperId())) {
            criteria.andEqualTo("moreUpperId", member.getMoreUpperId());
        }
        if (!StringUtils.isEmpty(member.getMoreUpperName())) {
            criteria.andLike("moreUpperName", StringUtils.fullFuzzy(member.getMoreUpperName()));
        }
        if (!StringUtils.isEmpty(member.getSubNum())) {
            criteria.andEqualTo("subNum", member.getSubNum());
        }
        if (!StringUtils.isEmpty(member.getSubValidNum())) {
            criteria.andEqualTo("subValidNum", member.getSubValidNum());
        }
        if (!StringUtils.isEmpty(member.getSubLowNum())) {
            criteria.andEqualTo("subLowNum", member.getSubLowNum());
        }
        if (!StringUtils.isEmpty(member.getGroupTotalNum())) {
            criteria.andEqualTo("groupTotalNum", member.getGroupTotalNum());
        }
        if (!StringUtils.isEmpty(member.getBirthdayTime())) {
            criteria.andEqualTo("birthdayTime", member.getBirthdayTime());
        }
        if (!StringUtils.isEmpty(member.getCreateTime())) {
            criteria.andEqualTo("createTime", member.getCreateTime());
        }
        if (!StringUtils.isEmpty(member.getCreateBy())) {
            criteria.andLike("createBy", StringUtils.fullFuzzy(member.getCreateBy()));
        }
        if (!StringUtils.isEmpty(member.getUpdateTime())) {
            criteria.andEqualTo("updateTime", member.getUpdateTime());
        }
        if (!StringUtils.isEmpty(member.getUpdateBy())) {
            criteria.andLike("updateBy", StringUtils.fullFuzzy(member.getUpdateBy()));
        }
        if (!StringUtils.isEmpty(member.getBalance())) {
            criteria.andEqualTo("balance", member.getBalance());
        }
        if (!StringUtils.isEmpty(member.getIntegral())) {
            criteria.andEqualTo("integral", member.getIntegral());
        }
        if (!StringUtils.isEmpty(member.getGoldCoin())) {
            criteria.andEqualTo("goldCoin", member.getGoldCoin());
        }
        example.orderBy("id").desc();
        List<Member> members = memberMapper.selectByExample(example);
        return members;
    }

    @Override
    public Member queryMemberById(Object id) {
        return memberMapper.selectByPrimaryKey(id);
    }


    @Override
    public void addMember(Member member) {
        memberMapper.insertSelective(member);
    }

    @Override
    public void removeMember(Long id) {
        Member member = new Member();
        member.setId(id);
        memberMapper.updateByPrimaryKeySelective(member);
    }

    @Override
    public void modifyMember(Member member) {
        memberMapper.updateByPrimaryKeySelective(member);
    }

}
